package com.fizzkai.p2p.core.service.impl;

import com.fizzkai.p2p.core.domain.SystemDictionaryItem;
import com.fizzkai.p2p.core.mapper.SystemDictionaryItemMapper;
import com.fizzkai.p2p.core.query.QueryObject;
import com.fizzkai.p2p.core.service.ISystemDictionaryItemService;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

@Service
@Transactional
public class SystemDictionaryItemServiceImpl implements ISystemDictionaryItemService {
    @Autowired
    private SystemDictionaryItemMapper dictionaryItemMapper;

    @Override
    public int saveOrUpdate(SystemDictionaryItem entity) {
        int row;
        if (entity.getId() == null) {
            row = dictionaryItemMapper.insert(entity);
        } else {
            row = dictionaryItemMapper.updateByPrimaryKey(entity);
        }
        return row;
    }

    @Override
    public PageInfo<SystemDictionaryItem> queryList(QueryObject qo) {
        PageHelper.startPage(qo.getPageNum(), qo.getPageSize());
        List<SystemDictionaryItem> list = dictionaryItemMapper.queryList(qo);
        return new PageInfo<>(list);
    }

    @Override
    public List<SystemDictionaryItem> queryListByParentSn(String sn) {
        return dictionaryItemMapper.queryListByParentSn(sn);
    }
}
